<template>
  <div>
    <van-icon
      :color="value ? 'red' : '#777'"
      :name="value ? 'star' : 'star-o'"
      @click="loading"
    />
  </div>
</template>

<script>
import { collectArticle, removecollectArticle } from '@/api/article'
export default {
  name: 'Collect',
  props: {
    value: {
      type: Boolean,
      required: true
    },
    aut_id: {
      type: String,
      required: true
    }
  },
  created() {},
  methods: {
    async loading() {
      try {
        if (!this.value) {
          await collectArticle({
            target: this.aut_id
          })
        } else {
          await removecollectArticle(this.aut_id)
        }
        this.$emit('input', !this.value)
        this.$toast(!this.value ? '收藏成功' : '取消收藏')
      } catch (error) {
        this.$toast('操作失败')
      }
    }
  }
}
</script>

<style lang="less" scoped></style>
